﻿/* QF classbuilder for Enlib */
using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Logging;

#region SYS_Department实体类
public class SYS_Department
{
	private string m_DeptID;
	private string m_DeptName;
	private string m_DeptShortName;
	private string m_DeptDescr;
	private string m_DeptNo;
	private int m_DeptLevel;
	private string m_ParentID;
	private DateTime m_CreateTime;
	private int m_Disabled;
	
	public SYS_Department ()
	{
		m_DeptID="";
		m_DeptName="";
		m_DeptShortName="";
		m_DeptDescr="";
		m_DeptNo="";
		m_DeptLevel=0;
		m_ParentID="";
		m_CreateTime=DateTime.Now;
		m_Disabled=0;
	}
	
	public string DeptID
	{
		get{return m_DeptID;}
		set{m_DeptID=value;}
	}
	public string DeptName
	{
		get{return m_DeptName;}
		set{m_DeptName=value;}
	}
	public string DeptShortName
	{
		get{return m_DeptShortName;}
		set{m_DeptShortName=value;}
	}
	public string DeptDescr
	{
		get{return m_DeptDescr;}
		set{m_DeptDescr=value;}
	}
	public string DeptNo
	{
		get{return m_DeptNo;}
		set{m_DeptNo=value;}
	}
	public int DeptLevel
	{
		get{return m_DeptLevel;}
		set{m_DeptLevel=value;}
	}
	public string ParentID
	{
		get{return m_ParentID;}
		set{m_ParentID=value;}
	}
	public DateTime CreateTime
	{
		get{return m_CreateTime;}
		set{m_CreateTime=value;}
	}
	public int Disabled
	{
		get{return m_Disabled;}
		set{m_Disabled=value;}
	}
}
#endregion

#region SYS_Department管理类
public partial class LogicLayer
{
	public bool AddSYS_Department(SYS_Department theSYS_Department)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "insert into SYS_Department (DeptID,DeptName,DeptShortName,DeptDescr,DeptNo,DeptLevel,ParentID,CreateTime,Disabled) values (@DeptID,@DeptName,@DeptShortName,@DeptDescr,@DeptNo,@DeptLevel,@ParentID,@CreateTime,@Disabled)";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			db.AddInParameter(cmd, "@DeptID", DbType.String, theSYS_Department.DeptID);
			db.AddInParameter(cmd, "@DeptName", DbType.String, theSYS_Department.DeptName);
			db.AddInParameter(cmd, "@DeptShortName", DbType.String, theSYS_Department.DeptShortName);
			db.AddInParameter(cmd, "@DeptDescr", DbType.String, theSYS_Department.DeptDescr);
			db.AddInParameter(cmd, "@DeptNo", DbType.String, theSYS_Department.DeptNo);
			db.AddInParameter(cmd, "@DeptLevel", DbType.Int32, theSYS_Department.DeptLevel);
			db.AddInParameter(cmd, "@ParentID", DbType.String, theSYS_Department.ParentID);
			db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, theSYS_Department.CreateTime);
			db.AddInParameter(cmd, "@Disabled", DbType.Int32, theSYS_Department.Disabled);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("AddSYS_Department:" + ex.Message );
			return false;
		}
	}
	
	public SYS_Department GetSYS_DepartmentFromDataReader(IDataReader dataReader)
	{
		try
		{
			SYS_Department result = new SYS_Department();
			
			if (dataReader["DeptID"] != null && dataReader["DeptID"] != System.DBNull.Value )
				result.DeptID = (string)dataReader["DeptID"];
			if (dataReader["DeptName"] != null && dataReader["DeptName"] != System.DBNull.Value )
				result.DeptName = (string)dataReader["DeptName"];
			if (dataReader["DeptShortName"] != null && dataReader["DeptShortName"] != System.DBNull.Value )
				result.DeptShortName = (string)dataReader["DeptShortName"];
			if (dataReader["DeptDescr"] != null && dataReader["DeptDescr"] != System.DBNull.Value )
				result.DeptDescr = (string)dataReader["DeptDescr"];
			if (dataReader["DeptNo"] != null && dataReader["DeptNo"] != System.DBNull.Value )
				result.DeptNo = (string)dataReader["DeptNo"];
			if (dataReader["DeptLevel"] != null && dataReader["DeptLevel"] != System.DBNull.Value )
				result.DeptLevel = (int)dataReader["DeptLevel"];
			if (dataReader["ParentID"] != null && dataReader["ParentID"] != System.DBNull.Value )
				result.ParentID = (string)dataReader["ParentID"];
			if (dataReader["CreateTime"] != null && dataReader["CreateTime"] != System.DBNull.Value )
				result.CreateTime = (DateTime)dataReader["CreateTime"];
			if (dataReader["Disabled"] != null && dataReader["Disabled"] != System.DBNull.Value )
				result.Disabled = (int)dataReader["Disabled"];
			
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("GetReaderSYS_Department:" + ex.Message);
			return null;
		}
	}
	
	public SYS_Department GetSYS_Department(string DeptID)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "select * From SYS_Department where DeptID=@DeptID";
			
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			db.AddInParameter(cmd, "@DeptID", DbType.String, DeptID);
			
			SYS_Department result = null;
			using (IDataReader dataReader = db.ExecuteReader(cmd))
			{
				if (dataReader.Read())
				{
					result = GetSYS_DepartmentFromDataReader( dataReader );
				}
			}
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("GetSYS_Department:" + ex.Message);
			return null;
		}
	}
	
	public bool DelSYS_Department(string DeptID)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "delete From SYS_Department where DeptID=@DeptID";
			
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			db.AddInParameter(cmd, "@DeptID", DbType.String, DeptID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("DelSYS_Department:" + ex.Message);
			return false;
		}
	}
	
	public bool UpdateSYS_Department(SYS_Department theSYS_Department)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "update SYS_Department set DeptName=@DeptName,DeptShortName=@DeptShortName,DeptDescr=@DeptDescr,DeptNo=@DeptNo,DeptLevel=@DeptLevel,ParentID=@ParentID,CreateTime=@CreateTime,Disabled=@Disabled where DeptID=@DeptID";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			db.AddInParameter(cmd, "@DeptName", DbType.String, theSYS_Department.DeptName);
			db.AddInParameter(cmd, "@DeptShortName", DbType.String, theSYS_Department.DeptShortName);
			db.AddInParameter(cmd, "@DeptDescr", DbType.String, theSYS_Department.DeptDescr);
			db.AddInParameter(cmd, "@DeptNo", DbType.String, theSYS_Department.DeptNo);
			db.AddInParameter(cmd, "@DeptLevel", DbType.Int32, theSYS_Department.DeptLevel);
			db.AddInParameter(cmd, "@ParentID", DbType.String, theSYS_Department.ParentID);
			db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, theSYS_Department.CreateTime);
			db.AddInParameter(cmd, "@Disabled", DbType.Int32, theSYS_Department.Disabled);
			db.AddInParameter(cmd, "@DeptID", DbType.String, theSYS_Department.DeptID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("UpdateSYS_Department:" + ex.Message);
			return false;
		}
	}
	
	public List<SYS_Department> ListSYS_Department()
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "select * from SYS_Department";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			 List<SYS_Department> result = new  List<SYS_Department>();
			using (IDataReader dataReader = db.ExecuteReader(cmd))
			{
				while (dataReader.Read())
				{
					SYS_Department obj = GetSYS_DepartmentFromDataReader( dataReader );
					if(obj != null)
						result.Add(obj);
				}
			}
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("ListSYS_Department:" + ex.Message);
			return null;
		}
	}
	
}
#endregion